package 力扣日常刷题.木23一月.第12天312;

/**
 * @author 帅小伙
 * @date 2022/3/12
 * @description
 */
public class Demo51连续子数组的最大和 {

    public int maxSubArray(int[] num) {
        int ans = num[0];
        int[] dp =  new int[num.length];
        dp[0] = num[0];

        for (int i = 1; i < num.length; i++) {
            dp[i] = Math.max(num[i],dp[i - 1] + num[i]);
            ans = Math.max(ans,dp[i]);
        }
        return ans;
    }
}
